import {Component, Input, OnInit} from '@angular/core';
import {Dbd} from "../../../../model/Dbd";
import {BakeProPlan} from "../../../../model/ProPlan";
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {AuthService} from "../../../../services/auth.service";

@Component({
  selector: 'app-sdckedit',
  templateUrl: './sdckedit.component.html',
  styleUrls: ['./sdckedit.component.css']
})
export class SdckeditComponent implements OnInit {
  @Input() o:BakeProPlan
  @Input() optype:string

  pmArray:Array<any>
 /* dbdwArray:Array<any>
  dbryArray:Array<any>
  ckrArray:Array<any>*/
  p:Dbd
  pmid:string
  constructor(private adminService:AdminService,
              private alertService:AlertService,
              private authService:AuthService) {
    this.p = new Dbd()
    this.pmArray = new Array()
 /*   this.dbdwArray = new Array()
    this.dbryArray = new Array()
    this.ckrArray = new Array()*/
  }

  ngOnInit(): void {

    this.p.scpc = this.o.proplanid;
    if(this.optype=="bcck"){
      this.p.type="包材"
      this.p.sqsl=this.o.jhbcsl
      this.pmid="cd6a249e86004f0c9c2f4aa252de522d"
    }else{
      this.p.type="咖啡"
      this.p.sqsl=this.o.jhsdyl
      this.pmid="d92b86068b2f4796960c685a7ff91c3e"
    }
    this.getPmArray();
  /*  this.getckrArray();
    this.getdbdwArray();
    this.getdbryArray();*/
  }

  getPmArray(){
    this.adminService.getNzSelCateByTypeid(this.pmid).then((data:any)=>{
      if(data.msg == "ok"){
        this.pmArray = data.list
      }else{
        this.alertService.showError("获取品名选择器失败")
      }
    })
  }
  /*getdbdwArray(){
    this.adminService.getReferdataSelectByTypeid("4dd5fa505ee64173bae1efa19dcd2b09").then((data:any)=>{
      if(data.msg == "ok"){
        this.dbdwArray = data.list
      }else{
        this.alertService.showError("获取调拨单位选择器失败")
      }
    })
  }
  getdbryArray(){
    this.authService.getMemberListByRole("c94ae62d6b5c442f9b11e667707d07a2").then((data:any)=>{
      if(data.msg == "ok"){
        this.dbryArray = data.list
      }else{
        this.alertService.showError("获取调拨人员选择器失败")
      }
    })
  }
  getckrArray(){
    this.authService.getMemberListByRole("adadad").then((data:any)=>{
      if(data.msg == "ok"){
        this.ckrArray = data.list
      }else{
        this.alertService.showError("获取出库人员选择器失败")
      }
    })
  }*/

  save(){
    this.adminService.saveDbd(this.p).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("设置出库成功")
      }else{
        this.alertService.showError("设置出库失败")
      }
    })
  }
}
